package org.cmg.study.spring.config;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author CMG
 * @version 1.0
 * @cLassName MyExceptionHandler
 * @description
 * @date 2021/9/6 13:46
 **/
public class MyExceptionHandler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        Map<String, Object> model = new HashMap<>();
        //根据不同错误转向不同页面(统一处理),即异常与view的对应关系
        if(e instanceof ArithmeticException){
            return new ModelAndView("error", model);
        }
        return new ModelAndView("error4", model);
    }
}
